﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Items_Items : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void dvItems_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
    {
        gvItem.DataBind();
    }
    protected void gvItem_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void gvBufabs_SelectedIndexChanged(object sender, EventArgs e)
    {
        InsertBufabs();    
    }
    protected void gvBufabs_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        
    }

    private void InsertBufabs()
    {
        string itemID = gvItem.SelectedValue.ToString() ;
        string bulfabMaterialID = gvBufabs.SelectedValue.ToString(); ;

        sdsInsFinalProduct.InsertCommand = "INSERT INTO [FinalProducts] ([ItemID], [BufabMaterialID]) VALUES (" + itemID + ", " + bulfabMaterialID + ")";
        sdsInsFinalProduct.Insert();
        gvBufabsList.DataBind();
    }

    private void InsertMaterials()
    {
        string itemID = gvItem.SelectedValue.ToString();
        string bulfabMaterialID = gvMaterials.SelectedValue.ToString(); 

        sdsInsFinalProduct.InsertCommand = "INSERT INTO [FinalProducts] ([ItemID], [BufabMaterialID]) VALUES (" + itemID + ", " + bulfabMaterialID + ")";
        sdsInsFinalProduct.Insert();
        gvMaterialsList.DataBind();
    }
    protected void gvMaterials_SelectedIndexChanged(object sender, EventArgs e)
    {
        InsertMaterials();
    }
    protected void dvItems_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
    {
        gvItem.DataBind();
    }
}
